package com.leyikao.util;

import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

import com.leyikao.entity.UserFormMap;

public class PasswordHelper {
	private RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
	private String algorithmName = "md5";
	private int hashIterations = 0;

	public void encryptPassword(UserFormMap userFormMap) {
		//本次改造为了配合cas系统 去掉了salt(盐值)   李阔 2016-5-25
	//	String salt=randomNumberGenerator.nextBytes().toHex();
	//	userFormMap.put("credentialsSalt", salt);
//		String newPassword = new SimpleHash(algorithmName, userFormMap.get("password"), ByteSource.Util.bytes(userFormMap.get("accountName")+salt), hashIterations).toHex();
		String newPassword = new SimpleHash(algorithmName, userFormMap.get("password"),"", hashIterations).toHex();
		userFormMap.put("password", newPassword); 
	}
	public static void main(String[] args) {
		PasswordHelper passwordHelper = new PasswordHelper();
		UserFormMap userFormMap = new UserFormMap();
		userFormMap.put("password","123456");
		userFormMap.put("accountName","123123");
		passwordHelper.encryptPassword(userFormMap);
		UsernamePasswordToken token = new UsernamePasswordToken("123123", "123456");
		System.out.println(userFormMap);
	}
}
